package org.xyz.util;

import android.content.Context;
import android.media.AudioManager;
import android.os.Vibrator;

/**
 * 
 * 辅助功能类,按钮震动，按钮声音.
 * 
 * @author dai.rui.lin
 * 
 */
public final class AssistHeper {

	public static boolean audio_flag;
	public static boolean vibrator_flag;

	final public static void openAudio(Context context) {
		if (audio_flag) {
			AudioManager am = (AudioManager) context
					.getSystemService(Context.AUDIO_SERVICE);
			// 设置声音模式，NORMAL（普通）
			// am.setMode(AudioManager.MODE_NORMAL);
			am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
			int mVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / 2;
			// 设置音量大小
			am.setStreamVolume(AudioManager.STREAM_MUSIC, mVolume, 0);
			am.adjustVolume(AudioManager.ADJUST_RAISE, 0);
		}
	}

	final public static void closeAudio(Context context) {
		AudioManager am = (AudioManager) context
				.getSystemService(Context.AUDIO_SERVICE);
		// 设置成静音模式
//		am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
		am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
	}

	/**
	 * @param context
	 *            上下文
	 * @param isOpen
	 *            是否振动
	 */
	final public static void openVibrator(Context context, boolean isOpen) {
		if (vibrator_flag) {
			if (isOpen) {
				Vibrator mVibrator = (Vibrator) context
						.getSystemService(Context.VIBRATOR_SERVICE);
				mVibrator.vibrate(new long[] { 10, 300 }, -1);
			}
		}
	}
	/**
	 * @param context
	 *            上下文
	 */
	final public static void openVibrator(Context context) {
				Vibrator mVibrator = (Vibrator) context
						.getSystemService(Context.VIBRATOR_SERVICE);
				mVibrator.vibrate(new long[] { 10, 300 }, -1);
	}
}
